package com.tutorialspoint;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import java.util.List;

public class MainApp {
    public static void main(String[] args) {
        ApplicationContext context = new ClassPathXmlApplicationContext("beans.xml");
        studentJDBCTemplate studentJDBCTemplate = (com.tutorialspoint.studentJDBCTemplate)context.getBean("jdbcTemplate");

        System.out.println("------Records Creation------");
        studentJDBCTemplate.create("xiaohuoche", 20);
        studentJDBCTemplate.create("055", 2);
        studentJDBCTemplate.create("little train", 3);

        System.out.println("------Listing Multiple Records------");
        List<Student> students = studentJDBCTemplate.listStudents();
        for (Student record : students
             ) {
            System.out.print("ID = " + record.getId());
            System.out.print(", Name = " + record.getName());
            System.out.println(", Age = " + record.getAge());
        }

        System.out.println("------Updating Record with id = 2------");
        studentJDBCTemplate.update(2,23);

        System.out.println("------Listing Record with ID = 2------");
        Student student = studentJDBCTemplate.getStudent(2);
        System.out.print("ID = " + student.getId());
        System.out.print(", Name = " + student.getName());
        System.out.println(", Age = " + student.getAge());
    }
}
